/*
 * Package: org.grassfield.common.service
 * FileName: AuditLogService.java
 *  
 * Created by pandian on Jan 28, 2011
 */
package service;

import java.util.Date;

import dao.IAuditLogDAO;
import dao.IUserDAO;
import bean.AuditLog;
import org.springframework.transaction.annotation.Transactional;


/**
 * The Class AuditLogService.
 */
public class AuditLogService implements IAuditLogService {
	private IAuditLogDAO auditLogDAO;
	private IUserDAO userDAO;

	/**
	 * Sets the audit log dao.
	 * 
	 * @param auditLogDAO the new audit log dao
	 */
	public void setAuditLogDAO(IAuditLogDAO auditLogDAO) {
		this.auditLogDAO = auditLogDAO;
	}

	/**
	 * Sets the user dao.
	 * 
	 * @param userDAO the new user dao
	 */
	public void setUserDAO(IUserDAO userDAO) {
		this.userDAO = userDAO;
	}

	@Override
	@Transactional
	public AuditLog add(AuditLog auditLog) {
		if (auditLog.getUser()==null){
			auditLog.setUser(this.userDAO.getUser(1));
		}
		auditLog.setLogTime(new Date());
		return auditLogDAO.add(auditLog);
	}
}
